package day7;

import java.util.Scanner;


public class BankAccount1 {
    String account;
    String password;
    double money;

    public BankAccount1(String account, String password, double money) {
        this.account = account;
        this.password = password;
        this.money = money;
    }

    public void addMoney(double money) throws InterruptedException {
        System.out.println("存钱");
        Thread.sleep(1000);
        this.money += money;
        System.out.println("存款成功");
    }

    public void minusMoney(double money) {
        System.out.println("取钱");
        System.out.println("请输入取款金额:");
        this.money -= money;
    }

    public double getMoney() {
        return money;
    }
}

class TestBankAccount1 {
    static Scanner sc = new Scanner(System.in);
    static BankAccount1 ba = new BankAccount1("admin","123456",202517);
    public static void main(String[] args) throws InterruptedException {
        one();
        System.out.println("退出系统");
    }
    //一级菜单
    public static void one() throws InterruptedException {
        while(true){
            System.out.println("******XXXX银行系统******");
            System.out.println("1.登录");
            System.out.println("2.退出");
            System.out.println("请输入编号");
            System.out.println("***********************");
            int n = sc.nextInt();
            switch(n){
                case 1:login();break;
                case 2:return;
            }
        }
    }
    //二级菜单
    public static void two() throws InterruptedException {
        while (true){
            System.out.println("******"+ba.account+"账号登陆成功******");
            System.out.println("1.存款");
            System.out.println("2.取款");
            System.out.println("3.查询余额");
            System.out.println("4.退出登陆");
            System.out.println("**********************");
            int n = sc.nextInt();
            switch(n){
                case 1:add();break;
                case 2:minus();return;
                case 3:get();return;
                case 4:return;
            }
        }
    }

    public static void login() throws InterruptedException {
        System.out.println("实现登录功能");
        for (int i=0;i<3;i++) {
            System.out.println("请输入账号:");
            String account = sc.next();
            System.out.println("请输入密码:");
            String password = sc.next();
            if ("admin".equals(account) && "123456".equals(password)) {
                two();
                return;
            }
            else {
                System.out.println("第"+(i+1)+"次输入账号密码错误");
            }
        }
        System.out.println("退出系统");
        System.exit(0);
    }
    public static void add() throws InterruptedException {
        System.out.println("xxx开始存钱");
        System.out.println("请输入存款金额:");
        double money = sc.nextDouble();
        ba.addMoney(money);
    }

    public static void get() throws InterruptedException {
        System.out.println("余额"+ba.account);
    }

    public static void minus(){
        for (int i=0;i<3;i++) {
            System.out.println("取款金额");
            double money = sc.nextDouble();
            if (money > ba.money) {
                System.out.println("余额不足");
                return;
            }
            else {
                ba.minusMoney(money);
                return;
            }
        }
    }
}
